Using addr_() on functions

Hello, I have an odd problem. This bit of DXL gives me an internal error:
 

void test()
{
    return
}
 
print (int addr_(test)) ""

 


While this bit of code works fine:

 

 

 

void test(string blah)
{
    return
}
 
print (int addr_(test)) ""



Why won't the first example work? Thanks!



 

 


SSloan - Tue Oct 12 15:36:28 EDT 2010

Re: Using addr_() on functions
Mathias Mamsch - Tue Oct 12 20:01:22 EDT 2010

The first example won't work since you cannot pass the function to the addr, if it has no parameters. DXL syntax makes test call the function and addr_ test trying to cast the (non-exististent) return value of test (after it called it) to int = ouch!

I found no syntax way, to get the address of a function without parameters, without calling it. If you find a way -> greatly appreciated :-) Regards, Mathias

Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Re: Using addr_() on functions
a_vestlin - Wed Oct 13 03:14:11 EDT 2010

Mathias Mamsch - Tue Oct 12 20:01:22 EDT 2010
The first example won't work since you cannot pass the function to the addr, if it has no parameters. DXL syntax makes test call the function and addr_ test trying to cast the (non-exististent) return value of test (after it called it) to int = ouch!

I found no syntax way, to get the address of a function without parameters, without calling it. If you find a way -> greatly appreciated :-) Regards, Mathias


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

This is only halfways, i haven't got it right for function returning nothing (void):

int getAddr(char pr(void))
{
 
    int a = (int addr_ pr)
        return(a)
}
 
char test()
{
        print "hello\n"
        return('0')
}
 
char getChar(char pr(void))
{
        return(pr)
}
int i
 
i = getAddr(test)
print i
char c = getChar(addr_ i)
print c

 


/Anders

 

Re: Using addr_() on functions
SystemAdmin - Fri Oct 15 14:50:13 EDT 2010

Problem solved

ABSTRACT:

DOORS blows up if you get the address of "void function(void)" function
directly. Alternate approach:
1) Pass in a dummy int parameter prior to the function parameter.
2) Figure out the address of the dummy parameter.
3) We know the temperamental function parameter content is 4 bytes ahead
of the dummy address.
4) Look four bytes ahead and extract an int that lies there.
5) Done

 

int* PtrOps_intStarAddressOf(_m &v) {
    int *val = &(addr_ (int (addr_ (v))));
    return (val);
}
 
int PtrOps_addressOfVar(_m& anyVar) {
    int temp = (int addr_ PtrOps_intStarAddressOf(anyVar));
    return temp;
}
 
int PtrOps_internalIntContentOfAddress(int& refToInt) {
    int content = refToInt;
    return content;
}
 
int PtrOps_intContentOfAddress(int address) {
    return (PtrOps_internalIntContentOfAddress(addr_ address));
}
 
 
int PtrOps_addressOfVoidFunctionWithNoParameterHelper(int dummyParameterOne, void function()) {
    int addressOfParameterOne;
    int contentOfParameterOne;
 
    int addressOfParameterTwo;
    int contentOfParameterTwo;
 
    addressOfParameterOne = PtrOps_addressOfVar(dummyParameterOne);
    contentOfParameterOne = PtrOps_intContentOfAddress(addressOfParameterOne);
 
    //--------------------------------------------------------------------------
        // DOORS blows up if you get the address of "void function(void)" function
        // directly.  Alternate approach:
        // 1) Pass in a dummy int parameter prior to the function parameter.
        // 2) Figure out the dummy address.
        // 3) We know the temperamental function parameter content is 4 bytes ahead.
        // 4) Look four bytes ahead and extract an int that lies there.
        // 5) Done
        //--------------------------------------------------------------------------
 
    addressOfParameterTwo = addressOfParameterOne + 4;
    contentOfParameterTwo = PtrOps_intContentOfAddress(addressOfParameterTwo);
 
    return contentOfParameterTwo;
}
 
int PtrOps_addressOfVoidFunctionWithNoParameter(void function()) {
    int dummyParameterOne = 1111;
    return PtrOps_addressOfVoidFunctionWithNoParameterHelper(dummyParameterOne, function);
}
 
int PtrOps_addressOfVoidFunctionWithOneNonRefParameter(void function(_m)) {
    return (int (addr_ function));
}
 
void callNoParameterVoidFunction(void function()) {
    function();
}
 
void callOneParameterVoidFunction(void function(_m)) {
    function("one");
}
 
void oneParameter(string msg) {
    print ">>> Hello from void function with " msg " parameter! <<<\n";
}
 
void noParameter() {
    print ">>> Hello from void function with no parameter! <<<\n";
}
 
void addressOfFunctionDemo() {
    print("I'm calling a one parameter void function directly\n");
    oneParameter("one");
    print("I'm calling a no parameter void function directly\n");
    noParameter();
 
    print("\n");
 
    print("I'm calling a one parameter void function by passing function by typed-function signature\n");
    callOneParameterVoidFunction( oneParameter );
    print("I'm calling a no parameter void function by passing function by typed-function signature\n");
    callNoParameterVoidFunction( noParameter );
 
    print("\n");
 
    int addressOfVoidFunctionWithOneNonRefParameter = PtrOps_addressOfVoidFunctionWithOneNonRefParameter( oneParameter );
    int addressOfVoidFunctionWithNoParameter = PtrOps_addressOfVoidFunctionWithNoParameter( noParameter );
 
    print("The address of a one parameter void function is (in decimal) " (addressOfVoidFunctionWithOneNonRefParameter) "\n");
    print("The address of a no parameter void function is (in decimal) " (addressOfVoidFunctionWithNoParameter) "\n");
 
    print("\n");
 
    print("I'm calling a one parameter void function by hacking-in the address\n");
    callOneParameterVoidFunction( addr_ addressOfVoidFunctionWithOneNonRefParameter );
 
    print("I'm calling a no parameter void function by hacking-in the address\n");
    callNoParameterVoidFunction( addr_ addressOfVoidFunctionWithNoParameter );
}
 
addressOfFunctionDemo();



OUTPUT:

I'm calling a one parameter void function directly
>>> Hello from void function with one parameter! <<<
I'm calling a no parameter void function directly
>>> Hello from void function with no parameter! <<<

I'm calling a one parameter void function by passing function by typed-function signature
>>> Hello from void function with one parameter! <<<
I'm calling a no parameter void function by passing function by typed-function signature
>>> Hello from void function with no parameter! <<<

I'm getting the address of a one parameter void function is (in decimal) 65726288
I'm getting the address of a no parameter void function is (in decimal) 65726312

I'm calling a one parameter void function by hacking-in the address
>>> Hello from void function with one parameter! <<<
I'm calling a no parameter void function by hacking-in the address
>>> Hello from void function with no parameter! <<<



 

Re: Using addr_() on functions
Mathias Mamsch - Fri Oct 15 15:18:13 EDT 2010

SystemAdmin - Fri Oct 15 14:50:13 EDT 2010

Problem solved

ABSTRACT:

DOORS blows up if you get the address of "void function(void)" function
directly. Alternate approach:
1) Pass in a dummy int parameter prior to the function parameter.
2) Figure out the address of the dummy parameter.
3) We know the temperamental function parameter content is 4 bytes ahead
of the dummy address.
4) Look four bytes ahead and extract an int that lies there.
5) Done

 

int* PtrOps_intStarAddressOf(_m &v) {
    int *val = &(addr_ (int (addr_ (v))));
    return (val);
}
 
int PtrOps_addressOfVar(_m& anyVar) {
    int temp = (int addr_ PtrOps_intStarAddressOf(anyVar));
    return temp;
}
 
int PtrOps_internalIntContentOfAddress(int& refToInt) {
    int content = refToInt;
    return content;
}
 
int PtrOps_intContentOfAddress(int address) {
    return (PtrOps_internalIntContentOfAddress(addr_ address));
}
 
 
int PtrOps_addressOfVoidFunctionWithNoParameterHelper(int dummyParameterOne, void function()) {
    int addressOfParameterOne;
    int contentOfParameterOne;
 
    int addressOfParameterTwo;
    int contentOfParameterTwo;
 
    addressOfParameterOne = PtrOps_addressOfVar(dummyParameterOne);
    contentOfParameterOne = PtrOps_intContentOfAddress(addressOfParameterOne);
 
    //--------------------------------------------------------------------------
        // DOORS blows up if you get the address of "void function(void)" function
        // directly.  Alternate approach:
        // 1) Pass in a dummy int parameter prior to the function parameter.
        // 2) Figure out the dummy address.
        // 3) We know the temperamental function parameter content is 4 bytes ahead.
        // 4) Look four bytes ahead and extract an int that lies there.
        // 5) Done
        //--------------------------------------------------------------------------
 
    addressOfParameterTwo = addressOfParameterOne + 4;
    contentOfParameterTwo = PtrOps_intContentOfAddress(addressOfParameterTwo);
 
    return contentOfParameterTwo;
}
 
int PtrOps_addressOfVoidFunctionWithNoParameter(void function()) {
    int dummyParameterOne = 1111;
    return PtrOps_addressOfVoidFunctionWithNoParameterHelper(dummyParameterOne, function);
}
 
int PtrOps_addressOfVoidFunctionWithOneNonRefParameter(void function(_m)) {
    return (int (addr_ function));
}
 
void callNoParameterVoidFunction(void function()) {
    function();
}
 
void callOneParameterVoidFunction(void function(_m)) {
    function("one");
}
 
void oneParameter(string msg) {
    print ">>> Hello from void function with " msg " parameter! <<<\n";
}
 
void noParameter() {
    print ">>> Hello from void function with no parameter! <<<\n";
}
 
void addressOfFunctionDemo() {
    print("I'm calling a one parameter void function directly\n");
    oneParameter("one");
    print("I'm calling a no parameter void function directly\n");
    noParameter();
 
    print("\n");
 
    print("I'm calling a one parameter void function by passing function by typed-function signature\n");
    callOneParameterVoidFunction( oneParameter );
    print("I'm calling a no parameter void function by passing function by typed-function signature\n");
    callNoParameterVoidFunction( noParameter );
 
    print("\n");
 
    int addressOfVoidFunctionWithOneNonRefParameter = PtrOps_addressOfVoidFunctionWithOneNonRefParameter( oneParameter );
    int addressOfVoidFunctionWithNoParameter = PtrOps_addressOfVoidFunctionWithNoParameter( noParameter );
 
    print("The address of a one parameter void function is (in decimal) " (addressOfVoidFunctionWithOneNonRefParameter) "\n");
    print("The address of a no parameter void function is (in decimal) " (addressOfVoidFunctionWithNoParameter) "\n");
 
    print("\n");
 
    print("I'm calling a one parameter void function by hacking-in the address\n");
    callOneParameterVoidFunction( addr_ addressOfVoidFunctionWithOneNonRefParameter );
 
    print("I'm calling a no parameter void function by hacking-in the address\n");
    callNoParameterVoidFunction( addr_ addressOfVoidFunctionWithNoParameter );
}
 
addressOfFunctionDemo();



OUTPUT:

I'm calling a one parameter void function directly
>>> Hello from void function with one parameter! <<<
I'm calling a no parameter void function directly
>>> Hello from void function with no parameter! <<<

I'm calling a one parameter void function by passing function by typed-function signature
>>> Hello from void function with one parameter! <<<
I'm calling a no parameter void function by passing function by typed-function signature
>>> Hello from void function with no parameter! <<<

I'm getting the address of a one parameter void function is (in decimal) 65726288
I'm getting the address of a no parameter void function is (in decimal) 65726312

I'm calling a one parameter void function by hacking-in the address
>>> Hello from void function with one parameter! <<<
I'm calling a no parameter void function by hacking-in the address
>>> Hello from void function with no parameter! <<<



 

Respectable hack! Grats :-)

Re: Using addr_() on functions
SystemAdmin - Fri Oct 15 16:26:35 EDT 2010

Mathias Mamsch - Fri Oct 15 15:18:13 EDT 2010
Respectable hack! Grats :-)

Vielen Dank -

When DXL throws in a banana peel onto the road (like crashing DOORS), we can either talk ourselves out of the need or use some C programming stunts to find an alternate route around the mess.

Re: Using addr_() on functions
TheRat - Sat Oct 25 11:26:13 EDT 2014

SystemAdmin - Fri Oct 15 16:26:35 EDT 2010
Vielen Dank -

When DXL throws in a banana peel onto the road (like crashing DOORS), we can either talk ourselves out of the need or use some C programming stunts to find an alternate route around the mess.

Do you think you could manage to do this for THIS problem?  Consider it a challenge!